package cn.macswelle.campusecurity.nvrlistener.controller;

import cn.macswelle.campusecurity.common.dto.requestDto.FaceRegDto;
import cn.macswelle.campusecurity.feignapi.deviceManager.RecordApi;
import cn.macswelle.campusecurity.sdk.DeviceInfo;
import cn.macswelle.campusecurity.sdk.controller.IndexController;
import cn.macswelle.campusecurity.sdk.service.AmqpService;
import org.bytedeco.javacpp.videoInputLib;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class MyIndexController extends IndexController {

  @Autowired
  private RecordApi recordApi;

  @PostMapping("/storeFace")
  @ResponseBody
  public String faceRegister(@RequestBody FaceRegDto faceRegDto) {
    return recordApi.register(faceRegDto);
  }

  @Override
  @RequestMapping("/")
  public ModelAndView index() {
    ModelAndView modelAndView = getIndexModelAndWiew();
    int a = videoInputLib.videoInput.listDevices();
    modelAndView.addObject("numr", a);
    modelAndView.addObject("num", Math.min(a, 4));
    return modelAndView;
  }
}
